//验证数据库中的用户
const User ={
    //查询手机号
    queryUserTel(option) {
        return 'select * from user where tel ='+option.userTel+'';
    },
    queryUserPwd(option) {
        return 'select * from user where (tel ='+option.userTel+') and pwd = '+option.userPwd+'';
    },
    // 新增用户
    insertData(option){
        let userTel = option.userTel;
        let userPwd = option.userPwd || '666666' ;

        //引入token包
        let jwt = require('jsonwebtoken');
        // //用户信息
        // let payload = {tel:userTel};
        // //口令
        // let sectet = 'guohuilong'
        //生成token
        let token = jwt.sign({ tel:userTel }, 'guohuilong',{
            expiresIn:'1h'
        });


        return 'insert into user (tel,pwd,imgUrl,nickName,token) values ("'+userTel+'","'+userPwd+'","","'+userTel+'","'+token+'")'
    },
    //修改用户密码（找回密码）
    updateUserPwd(option,results){
        let userTel = option.userTel;
        let userPwd = option.userPwd;
        let id = results[0].id;
        let pwd = results[0].pwd;
        return 'update user set pwd = replace(pwd,'+pwd+','+userPwd+') where id = '+id+''
    }
}

exports = module.exports = User;